var blockly2 = {
		initBlockly2:function(){
			var Deal = document.getElementById("Deal");
			var Data = document.getElementById("Data");
			var DataArr = [];
			var DealArr = [];
			Blockly.Blocks['MACD'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("MACD");
			    this.setOutput(true, null);
			    this.setColour(110);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['MACD'] = function(block) {
				var code = "'MACD'";
			  return [code];
			};
			Blockly.Blocks['Open'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("open");
			    this.setOutput(true, "Number");
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['Open'] = function(block) {
				var code = "'open'";
			  return [code];
			};
			Blockly.Blocks['time'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("data['time']");
			    this.setColour(120);
			    this.setOutput(true,null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['time'] = function(block) {
				var code = "data['time']";
			  return [code];
			};
			Blockly.Blocks['close'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("close");
			    this.setOutput(true, null);
			    this.setColour(130);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['close'] = function(block) {
				var code = "'close'";
			  return [code];
			};
			Blockly.Blocks['MA5'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("MA5");
			    this.setOutput(true, null);
			    this.setColour(140);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['MA5'] = function(block) {
				var code = "'MA5'";
			  return [code];
			};
			Blockly.Blocks['Buy'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("Buy")
			        .appendField(new Blockly.FieldNumber(0, 0, Infinity, 10), "Buy");
			    this.setColour(150);
			    this.setPreviousStatement(true, null);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['Buy'] = function(block) {
				var buy = block.getFieldValue("Buy");
				return "			self.buy("+buy+")\n		";
			};
			Blockly.Blocks['Sell'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("Sell")
			        .appendField(new Blockly.FieldNumber(0, 0, Infinity, 10), "Sell");
			    this.setColour(160);
			    this.setPreviousStatement(true, null);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['Sell'] = function(block) {
				var sell = block.getFieldValue("Sell");
			  return "			self.sell("+sell+")\n		";
			};
			Blockly.Blocks['Num'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("history_day(num=")
			        .appendField(new Blockly.FieldNumber(100), "Num")
			        .appendField(")");
			    this.setColour(170);
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['Num'] = function(block) {
				var num = block.getFieldValue("Num");
				var code = "self.history_day(num="+num+")"
				return [code, Blockly.Python.ORDER_NONE];
			};
			Blockly.Blocks['history_min'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("history_min(")
			        .appendField(new Blockly.FieldNumber(300), "history_min")
			        .appendField(")");
			    this.setOutput(true, null);
			    this.setColour(180);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['history_min'] = function(block) {
				var num = block.getFieldValue("history_min");
				var code = "self.history_min("+num+")"
				return [code, Blockly.Python.ORDER_NONE];
			};

			
			Blockly.Blocks['index'] = {
			  init: function() {
				this.appendValueInput("param")
		        	.setCheck(null)
		        	.appendField("[");
			    this.appendDummyInput()
			    	.appendField("]")
			    this.setOutput(true, null);
			    this.setColour(190);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['index'] = function(block) {
				var param = Blockly.Python.valueToCode(block,"param");
				var code = "["+param+"]";
			  return [code];
			};
			
			Blockly.Blocks['ndarray'] = {
			  init: function() {
			    this.appendValueInput("Time")
			        .setCheck(['time'])
			        .appendField("type(");
			    this.setColour(200);
			    this.appendDummyInput()
			        .appendField(")is np.ndarray");
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['ndarray'] = function(block) {
				var time = Blockly.Python.valueToCode(block, 'Time');
				var code = "type("+time+") is np.ndarray";
			  return [code];
			};
			
			
			Blockly.Blocks['variate'] = {
			  init: function() {
			    this.appendValueInput("method")
			        .setCheck(null)
			        .appendField('变量')
			        .appendField(new Blockly.FieldVariable("df"), "df");
			    this.setColour(210);
			    this.setOutput(true,null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['variate'] = function(block) {
			  var variable_varname = block.getFieldValue('df');
			  var value_method = Blockly.Python.valueToCode(block, 'method');
			  var index = value_method.indexOf(".");
			  if(value_method!=null && value_method!='' && index!=0){
				  value_method = "["+value_method+"]"
			  }
			  var code = variable_varname+value_method;
			  return [code];
			};
			Blockly.Blocks['var'] = {
			  init: function() {
			    this.appendValueInput("param")
			        .setCheck(null)
			        .appendField('变量')
			        .appendField(new Blockly.FieldVariable("df"), "df");
			    this.setPreviousStatement(true, null);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['var'] = function(block) {
			  var variable_var = Blockly.Python.variableDB_.getName(block.getFieldValue('df'), Blockly.Variables.NAME_TYPE);
			  var value_param = Blockly.Python.valueToCode(block, 'param', Blockly.Python.ORDER_ATOMIC);
			  var index = value_param.indexOf(".");
			  if(value_param!=null && value_param!='' && index!=0){
				  value_param = "["+value_param+"]"
			  }
			  var code = variable_var+value_param;
			  return code;
			};
			Blockly.Blocks['at'] = {
			  init: function() {
			    this.appendValueInput("param1")
			        .setCheck(null)
			        .appendField(".at(")
			        .appendField("param1");
			    this.appendValueInput("param2")
			        .setCheck(null)
			        .appendField(",param2)");
			    this.appendValueInput("index")
			    	.appendField("[index]")
			        .setCheck("Number")
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['at'] = function(block) {
			  var value_param1 = Blockly.Python.valueToCode(block, 'param1', Blockly.Python.ORDER_ATOMIC);
			  var value_param2 = Blockly.Python.valueToCode(block, 'param2', Blockly.Python.ORDER_ATOMIC);
			  var value_index = Blockly.Python.valueToCode(block, 'index', Blockly.Python.ORDER_ATOMIC);
			  var index = value_index.indexOf("[");
			  if(value_index!=null && value_index!='' && index==-1){
				  value_index = "["+value_index+"]";
			  }
			  var code = ".at["+value_param1+","+value_param2+"]"+value_index;
			  return [code, Blockly.Python.ORDER_NONE];
			};
			Blockly.Blocks['zzsq'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("战争士气")
			        .appendField(new Blockly.FieldDropdown([["主力", "主力"], ["趋势", "趋势"], ["多前锋", "多前锋"], ["空前锋", "空前锋"], ["压力", "压力"], ["ZZSQ方向", "ZZSQ方向"], ["强M", "强M"], ["变", "变"], ["风险", "风险"], ["强弱", "强弱"]]), "战争士气");
			    this.setOutput(true, null);
			    this.setColour(230);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['zzsq'] = function(block) {
			  var dropdown = block.getFieldValue('战争士气');
			  var code = "'"+dropdown+"'";
			  return [code];
			};
			Blockly.Blocks['zzll'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("战争力量")
			        .appendField(new Blockly.FieldDropdown([["volume", "volume"],["RefMax341", "RefMax341"],["Ref压力1", "Ref压力1"],["多头C空头", "多头C空头"],["人心C空头", "人心C空头"],["空头", "空头"],["多头", "多头"],["Ref多头1", "Ref多头1"],["多空比", "多空比"],["Max34", "Max34"], ["压力", "压力"], ["人心", "人心"], ["量心比", "量心比"], ["压力", "压力"], ["ZZLL量比", "ZZLL量比"]]), "战争力量")
			    this.setOutput(true, null);
			    this.setColour(240);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['zzll'] = function(block) {
			  var dropdown = block.getFieldValue('战争力量');
			  var code = "'"+dropdown+"'";
			  return [code];
			};
			Blockly.Blocks['fx'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("风险")
			        .appendField(new Blockly.FieldDropdown([["牛","牛"],["blast人心<=多头","blast人心<=多头"],["blast多头<空头","blast多头<空头"],["ZTPower","ZTPower"],["ZZLL方向", "ZZLL方向"], ["RefZZLL方向1", "RefZZLL方向1"], ["ZZLLPower", "ZZLLPower"], ["Ref人心1", "Ref人心1"], ["主图方向", "主图方向"], ["Ref主图方向1", "Ref主图方向1"], ["Ref趋势1", "Ref趋势1"]]), "FX");
			    this.setOutput(true, null);
			    this.setColour(250);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['fx'] = function(block) {
				  var dropdown_name = block.getFieldValue('FX');
				  var code = "'"+dropdown_name+"'";
				  return [code];
				};
			Blockly.Blocks['qr'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField("强弱")
			        .appendField(new Blockly.FieldDropdown([["high", "high"], ["low", "low"], ["Refhigh1", "Refhigh1"], ["Reflow1", "Reflow1"]]), "强弱")
			    this.setOutput(true, null);
			    this.setColour(260);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['qr'] = function(block) {
			  var dropdown = block.getFieldValue('强弱');
			  var code = "'"+dropdown+"'";
			  return [code];
			};
			Blockly.Blocks['operation'] = {
			  init: function() {
			    this.appendValueInput("operationParam")
			        .setCheck("Number")
			        .appendField(new Blockly.FieldDropdown([["=", "="], ["+", "+"], ["-", "-"], ["*", "*"], ["/", "/"]]), "operation");
			    this.setPreviousStatement(true, null);
			    this.setColour(270);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['operation'] = function(block) {
			  var dropdown_operation = block.getFieldValue('operation');
			  var statements_operationParam = Blockly.Python.valueToCode(block, 'operationParam');
			  var index = statements_operationParam.indexOf(",");
			  if(index==2){
				  statements_operationParam = statements_operationParam.substring(3);
			  }
			  var code = dropdown_operation+statements_operationParam;
			  return code;
			};
			Blockly.Blocks['talib'] = {
			  init: function() {
			    this.appendStatementInput("talibParam")
			        .setCheck(null)
			        .appendField("talib方法")
			        .appendField(new Blockly.FieldDropdown([ ["EMA", "EMA"],["LINEARREG_SLOPE", "LINEARREG_SLOPE"], ["SMA", "SMA"], ["MIN", "MIN"], ["MAX", "MAX"]]), "talibfun");
			    this.setPreviousStatement(true, null);
			    this.setColour(280);
			    this.setOutput(true,null);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['talib'] = function(block) {
			  var dropdown_talibfun = block.getFieldValue('talibfun');
			  var statements_talibParam = Blockly.Python.statementToCode(block, 'talibParam');
			  var code = "tablib."+dropdown_talibfun+"("+statements_talibParam+")";
			  return [code, Blockly.Python.ORDER_NONE];
			};
			Blockly.Blocks['nparray'] = {
			  init: function() {
			    this.appendValueInput("nparray")
			        .setCheck(null)
			        .appendField("np.array(")
			    this.setPreviousStatement(true, null);
			    this.setColour(290);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['nparray'] = function(block) {
			  var value_nparray = Blockly.Python.valueToCode(block, 'nparray');
			  var code = "np.array("+value_nparray+")";
			  return code;
			};
			Blockly.Blocks['dummynum'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField(new Blockly.FieldNumber(0), "dummyNum");
			    this.setPreviousStatement(true, null);
			    this.setColour(300);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['dummynum'] = function(block) {
			  var number_dummynum = block.getFieldValue('dummyNum');
			  var code = ','+number_dummynum;
			  return code;
			};
			Blockly.Blocks['self_ref'] = {
			  init: function() {
			    this.appendValueInput("var")
			        .setCheck(null)
			        .appendField("self.ref(")
			        .appendField("变量,");
			    this.appendValueInput("zz")
			        .setCheck(null)
			        .appendField("     战争,");
			    this.appendValueInput("num")
			        .setCheck(null)
			        .appendField("     数值)");
			    //this.setPreviousStatement(true, null);
			    //this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			    this.setColour(310);
			  }
			};
			Blockly.Python['self_ref'] = function(block) {
			  var value_var = Blockly.Python.valueToCode(block, 'var', Blockly.Python.ORDER_ATOMIC);
			  var value_zz = Blockly.Python.valueToCode(block, 'zz', Blockly.Python.ORDER_ATOMIC);
			  var value_num = Blockly.Python.valueToCode(block, 'num', Blockly.Python.ORDER_ATOMIC);
			  var code = "self.ref("+value_var+","+value_zz+","+value_num+")";
			  return code;
			};
			Blockly.Blocks['for'] = {
			  init: function() {
			    this.appendValueInput("var")
			        .setCheck("String")
			        .appendField("for");
			    this.appendValueInput("len")
			        .setCheck("Number")
			        .appendField("in")
			        .appendField("range")
			        .appendField("(");
			    this.appendDummyInput()
			        .appendField(")");
			    this.appendStatementInput("context")
			        .setCheck(null);
			    this.setPreviousStatement(true, null);
			    this.setColour(320);
			    this.setNextStatement(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['for'] = function(block) {
			  var value_var = Blockly.Python.valueToCode(block, 'var', Blockly.Python.ORDER_ATOMIC);
			  var value_len = Blockly.Python.valueToCode(block, 'len', Blockly.Python.ORDER_ATOMIC);
			  var statements_context = Blockly.Python.statementToCode(block, 'context');
			  var code ="for "+value_var+" in range("+value_len+"):\n\t"+statements_context;
			  return code;
			};
			Blockly.Blocks['len'] = {
			  init: function() {
			    this.appendValueInput("len")
			        .setCheck(null)
			        .appendField("len(");
			    this.setOutput(true, "Number");
			    this.appendDummyInput()
		        .appendField(")");
			    this.setColour(330);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['len'] = function(block) {
			  var value_len = Blockly.Python.valueToCode(block, 'len', Blockly.Python.ORDER_ATOMIC);
			  var code = "len("+value_len+")";
			  return [code];
			};
			Blockly.Blocks['abs'] = {
			  init: function() {
			    this.appendValueInput("context")
			        .setCheck(null)
			        .appendField("abs（");
			    this.appendDummyInput()
			        .appendField(")");
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['abs'] = function(block) {
			  var value_context = Blockly.Python.valueToCode(block, 'context', Blockly.Python.ORDER_ATOMIC);
			  var code = "abs("+value_context+")";;
			  return [code];
			};
			Blockly.Blocks['append'] = {
			  init: function() {
			    this.appendValueInput("context")
			        .setCheck(null)
			        .appendField(".append(");
			    this.appendDummyInput()
			        .appendField(")");
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['append'] = function(block) {
			  var value_context = Blockly.Python.valueToCode(block, 'context', Blockly.Python.ORDER_ATOMIC);
			  var code = ".append("+value_context+")";
			  return [code, Blockly.Python.ORDER_NONE];
			};
			Blockly.Blocks['self_cross'] = {
			  init: function() {
			    this.appendValueInput("param1")
			        .setCheck(null)
			        .appendField("self.cross(")
			        .appendField("param1,");
			    this.appendValueInput("param2")
			        .setCheck(null)
			        .appendField("       param2,");
			    this.appendValueInput("param3")
			        .setCheck(null)
			        .appendField("       param3,");
			    this.appendValueInput("param4")
			        .setCheck(null)
			        .appendField("       param4)");
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['self_cross'] = function(block) {
			  var value_param1 = Blockly.Python.valueToCode(block, 'param1', Blockly.Python.ORDER_ATOMIC);
			  var value_param2 = Blockly.Python.valueToCode(block, 'param2', Blockly.Python.ORDER_ATOMIC);
			  var value_param3 = Blockly.Python.valueToCode(block, 'param3', Blockly.Python.ORDER_ATOMIC);
			  var value_param4 = Blockly.Python.valueToCode(block, 'param4', Blockly.Python.ORDER_ATOMIC);
			  var code = "sel.cross("+value_param1+","+value_param2+","+value_param3+","+value_param4+")";
			  return code;
			};
			Blockly.Blocks['self_last'] = {
			  init: function() {
			    this.appendValueInput("param1")
			        .setCheck(null)
			        .appendField("self.last(")
			        .appendField("param1,");
			    this.appendValueInput("param2")
			        .setCheck(null)
			        .appendField("       param2,");
			    this.appendValueInput("param3")
			        .setCheck(null)
			        .appendField("       param3,");
			    this.appendValueInput("param4")
			        .setCheck(null)
			        .appendField("       param4)");
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['self_last'] = function(block) {
			  var value_param1 = Blockly.Python.valueToCode(block, 'param1', Blockly.Python.ORDER_ATOMIC);
			  var value_param2 = Blockly.Python.valueToCode(block, 'param2', Blockly.Python.ORDER_ATOMIC);
			  var value_param3 = Blockly.Python.valueToCode(block, 'param3', Blockly.Python.ORDER_ATOMIC);
			  var value_param4 = Blockly.Python.valueToCode(block, 'param4', Blockly.Python.ORDER_ATOMIC);
			  var code = "sel.last("+value_param1+","+value_param2+","+value_param3+","+value_param4+")";
			  return code;
			};
			Blockly.Blocks['self_barslast'] = {
			  init: function() {
			    this.appendValueInput("param1")
			        .setCheck(null)
			        .appendField("self.last(")
			        .appendField("param1,");
			    this.appendValueInput("param2")
			        .setCheck(null)
			        .appendField("       param2,");
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['self_barslast'] = function(block) {
			  var value_param1 = Blockly.Python.valueToCode(block, 'param1', Blockly.Python.ORDER_ATOMIC);
			  var value_param2 = Blockly.Python.valueToCode(block, 'param2', Blockly.Python.ORDER_ATOMIC);
			  var code = "sel.barslast("+value_param1+","+value_param2+")";
			  return code;
			};
			Blockly.Blocks['sign'] = {
			  init: function() {
			    this.appendDummyInput()
			        .appendField(new Blockly.FieldDropdown([[">", ">"], ["≥",">="], ["=", "=="], ["≤","<="], ["<", "<"]]), "sign");
			    this.setOutput(true, null);
			    this.setTooltip('');
			    this.setHelpUrl('http://www.example.com/');
			  }
			};
			Blockly.Python['sign'] = function(block) {
			  var dropdown_name = block.getFieldValue('sign');
			  var code ="'"+dropdown_name+"'";
			  return [code, Blockly.Python.ORDER_NONE];
			};
			DataArr.push("<block type='Open'></block>")
			DataArr.push("<block type='MACD'></block>")
			DataArr.push("<block type='close'></block>")
			DataArr.push("<block type='time'></block>")
			DataArr.push("<block type='MA5'></block>")
			DataArr.push("<block type='Num'></block>")
			DataArr.push("<block type='len'></block>")
			DataArr.push("<block type='math_number'></block>")
			DataArr.push("<block type='for'></block>")
			DataArr.push("<block type='append'></block>")
			DataArr.push("<block type='abs'></block>")
			DataArr.push("<block type='dummynum'></block>")
			DataArr.push("<block type='history_min'></block>")
			DataArr.push("<block type='index'></block>")
			DataArr.push("<block type='ndarray'></block>")
			DataArr.push("<block type='at'></block>")
			DataArr.push("<block type='operation'></block>")
			DataArr.push("<block type='self_ref'></block>")
			DataArr.push("<block type='self_last'></block>")
			DataArr.push("<block type='self_barslast'></block>")
			DataArr.push("<block type='variate'></block>")
			DataArr.push("<block type='var'></block>")
			DataArr.push("<block type='zzsq'></block>")
			DataArr.push("<block type='zzll'></block>")
			DataArr.push("<block type='qr'></block>")
			DataArr.push("<block type='fx'></block>")
			DataArr.push("<block type='talib'></block>")
			DataArr.push("<block type='nparray'></block>")
			
			
			Data.innerHTML = DataArr.join("");
			
			DealArr.push("<block type='Buy'></block>")
			DealArr.push("<block type='Sell'></block>")
			Deal.innerHTML = DealArr.join("");
		},
		newPythonFile:function(code){
			console.log(code);
			$.ajax({
				type:"POST",
				url:"newPythonFile",
				data:{"code":"	"+code},
				success:function(result){
					alert(result);
					console.log("创建:"+result);
				}
			});
		}
}